//用户管理模块相关的api
import request from "../../../utils/request.ts";
import type {T_User, T_UserResponseData, T_AllRoleResponseData, T_SetRoleData} from "./type.ts";


//枚举地址

enum API {
    //获取全部已有用户账号信息
    ALLUSER_URL = "/admin/acl/user/",
    //添加一个新用户
    ADDUSER_URL = "/admin/acl/user/save",
    //更新已有账号信息
    UPDATEUSER = "/admin/acl/user/update",
    //根据账户id获取职位信息
    ALLROLE_URL = "/admin/acl/user/toAssign/",
    //给已有用户分配职位接口
    SETROLE_URL = "/admin/acl/user/doAssignRole",
    //删除某一个账号
    DELETEUSER_URL = "/admin/acl/user/remove/",
    //批量删除
    DELETEALLUSER_URL = "/admin/acl/user/batchRemove"
}

//获取用户信息的接口方法
export const reqGetUserInfo = (page: number, limit: number, username: string) => request.get<any, T_UserResponseData>(API.ALLUSER_URL + `${page}/${limit}/?username=${username}`);

//添加/修改用户
export const reqAddOrUpdateUser = (data: T_User) => {
    if (data.id) {
        //修改
        return request.put<any, any>(API.UPDATEUSER, data);
    } else {
        //添加
        return request.post<any, any>(API.ADDUSER_URL, data);
    }
};

//获取全部职位以及包含当前用户已有的职位
export const reqAllRole = (userId: number) => request.get<any, T_AllRoleResponseData>(API.ALLROLE_URL + userId);

//分配职位
export const reqSetUserRole = (data: T_SetRoleData) => request.post<any, any>(API.SETROLE_URL, data);

//删除某一个账号信息
export const reqRemoveUser = (userId: number) => request.delete<any, any>(API.DELETEUSER_URL + userId);

//批量删除的接口
export const reqBatRemoveUser = (idList: number[]) => request.delete<any, any>(API.DELETEALLUSER_URL, {data: idList});
